
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state={
  num:1
}

const mutations={
  add(state){
    state.num++
  },
  reduce(state,n){
    state.num-=n
  }
}

const getters={
  toNum:state=>state.num+=10
}

// 可以调用Mutations里面的方法
const actions={
  addAction({commit}){
    commit('add')
  },
  reduceAction({commit},n){
    commit('reduce',n)
  }
}

const option={
  state,
  mutations,
  getters,
  actions
}
export default new Vuex.Store({
  modules:{option}
})
